{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['01_引用.md', '02_数据类型.md', '03_运算符.md', '04_数组.md', '05_函数.md']"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import re\n",
    "md_list = [x for x in os.listdir() if re.match(r'^(?!00_目录).*\\.md$', x)]\n",
    "md_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "title_list=['# 目录']\n",
    "for f in md_list:\n",
    "    title=open(f,'r',encoding='utf-8')\n",
    "    title=[x for x in title if re.match('^##.*&ensp;.*\\\\n',x)]\n",
    "    title=[f'[{''.join(re.findall(r'^##.* (.*)&ensp;(.+)\\n',title[1])[0])}]({f} {re.search('(.*)\\n',x).group(1)})' for x in title]\n",
    "    title_list.extend(title)\n",
    "with open('00_目录.md','w',encoding='utf-8') as f:\n",
    "    f.write('\\n'.join(title_list))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
